<?php

namespace ProjetA\GroupeBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
//use ProjetA\GroupeBundle\Controller\GroupeController as groupe;
use ProjetA\GroupeBundle\Entity\Page as Page;
use ProjetA\GroupeBundle\Entity\Groupe as Groupe;



use ProjetA\GroupeBundle\Form\PageGroupeType;


class GroupeType extends AbstractType {
    
    protected  $page;
    protected $username;
    protected $groupe;
    function __construct(Page $page,$username, Groupe $groupe = null) {
        $this->page = $page;
        $this->username=$username;
        $this->groupe = $groupe;
    }

        public function buildForm(FormBuilder $builder, array $options) {
        $builder
                ->add('nom')
                ->add('description', 'textarea', array('max_length' => '500'))
                ->add('page_id', 'hidden', array('data' => $this->page->getId(),'property_path' => false))
                ->add('moderateur_username', 'hidden', array('data' => $this->username,'property_path' => false))
                ->add('public', 'choice', array(
                    'choices'   => array('0' => 'Privé', '1' => 'Public'),
                    'expanded' => true, 
                    'preferred_choices' => array(1),
                    'label'     => 'Rendre votre groupe :',
                    'required'  => true));
                if($this->edit()){
                     $builder->add('page',new PageGroupeType($this->page,$this->groupe), array('property_path' => false));
                }else{
                     $builder->add('page',new PageGroupeType($this->page), array('property_path' => false));
                }
               
                    $builder->add('tags', 'collection', array(
                    'type' => new TagType(),
                    'allow_add' => true,
                    'prototype'=>true,
                    //'by_reference' => false,
                ));
    }

    public function getName() {
        return 'projeta_groupebundle_groupetype';
    }
    Public function edit(){
        if($this->groupe != null){
            return true;
        }else{
            return false;
        }
    }
}
